import {defineConfig} from 'vite'
import react from '@vitejs/plugin-react'
import WindiCSS from 'vite-plugin-windicss'
import {viteMockServe} from 'vite-plugin-mock';
import path from 'path';


// https://vitejs.dev/config/
// export default defineConfig({
//   plugins: [react(),WindiCSS(),],
//   server:{
//     port:5000,
//     proxy: {
//       // 选项写法
//       '/api': {
//         target: 'http://jsonplaceholder.typicode.com',
//         changeOrigin: true,
//         rewrite: (path) => path.replace(/^\/api/, '')
//       },
//     }
//   },
// })
export default ({command}) => {
  console.log("当前使用的指令是", command)
  return {
    plugins: [
      react(), WindiCSS(),
      viteMockServe({
        // default
        mockPath: 'mock',
        localEnabled: command === 'serve',
      }),
    ],
    resolve: {
      alias: [
        {find: "src", replacement: path.resolve(__dirname, 'src')},
      ]
    },
    server: {
      port: 5000,
      proxy: {
        // 选项写法
        '/api': {
          target: 'http://127.0.0.1:8000',
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, '')
        },
      }
    },
  }
}